import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_with_bmap/models/vehicle_hv_info.dart';
import 'package:provider/provider.dart';

class Pannel extends StatefulWidget {
  const Pannel({super.key});

  @override
  State<StatefulWidget> createState() {
    return PannelState();
  }
}

class PannelState extends State<Pannel> {
  @override
  Widget build(BuildContext context) {
    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
      Builder(builder: (context) {
        return GestureDetector(
          onTap: () {
            Scaffold.of(context).openDrawer();
          },
          child: const Image(
              image: AssetImage("flutter_assets/images/btn-setting.png"),
              width: 30),
        );
      }),
      Container(
          margin: const EdgeInsets.fromLTRB(0, 20, 0, 0),
          child: Stack(alignment: AlignmentDirectional.center, children: [
            const Image(
                image: AssetImage("flutter_assets/images/compass.png"),
                width: 70),
            Consumer<VehicleHvInfo>(builder: (context, value, child) {
              return Transform.rotate(
                  angle: pi / 180 * (value.info?.head ?? 0),
                  child: const Image(
                      image: AssetImage("flutter_assets/images/direction.png"),
                      width: 15));
            })
          ])),
      Container(
          width: 70,
          height: 70,
          margin: const EdgeInsets.fromLTRB(0, 20, 0, 0),
          decoration: BoxDecoration(
            borderRadius: const BorderRadius.all(Radius.circular(100)),
            border: Border.all(
                color: Colors.blue, width: 2, style: BorderStyle.solid),
          ),
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
            Selector(
              builder: ((context, speed, child) {
                return Text(speed?.toString() ?? "--");
              }),
              selector: (BuildContext context, VehicleHvInfo vehicleHvInfo) {
                return vehicleHvInfo.info?.speed.toInt();
              },
            ),
            const Text("km/h")
          ]))
    ]);
  }
}
